package com.gmall.search.controller;

import com.gmall.common.result.Result;
import com.gmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/search")
public class SearchController {


    @Autowired
    SearchService searchService;

    @PostMapping("{page}/{size}")
    public Result<Map> search(@PathVariable Integer page,
                      @PathVariable Integer size,
                      @RequestBody Map searchMap) throws IOException, ParseException {
        return searchService.search(page,size,searchMap);
    }

    public static void main(String[] args) {
        String path = "api/search/1/10";
        String[] strings = StringUtils.tokenizeToStringArray(path, "/");
        String newPath = "/" +
                (String) Arrays.stream(strings)
                        .skip(1)
                        .collect(Collectors.joining("/"));

    }

}
